﻿using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using shaco.ActionExtensions;

namespace ShootMan
{
    [shaco.UILayerIndex((int)ShootMan.GlobalDefines.UILayers.Game)]
    [shaco.UILayerOpenAsync]
    public class EndLayer : UnityEngine.MonoBehaviour, shaco.IUIAnimation
    {
        public Text textTotalShootCount;
        public Button buttonEnd;

        void OnUIOpen(shaco.Base.BaseEventArg arg)
        {
            var gameLayer = shaco.GameHelper.ui.GetUIComponent<GameLayer>();
            this.textTotalShootCount.text = shaco.GameHelper.localization.GetTextFormat("EndLayer_GameOver", gameLayer.totalShootCount);
            this.buttonEnd.onClick.AddListener(() => this.CloseMe());
        }

        void OnUIClose()
        {
            shaco.Log.Info("EndLayer OnUIClose...");
            GameRoot.DestroyRoot();
            shaco.GameHelper.ui.OpenUI<MainLayer>();
        }

        void OnDestroy()
        {
            shaco.Log.Info("EndLayer OnDestroy: will back to MainScene");
        }

        public IEnumerator RunUIOpenAnimation()
        {
            shaco.GameHelper.sound.Play($"{ShootMan.GlobalDefines.HOTUPDATE_ROOT}Audio/ui_show.wav");
            yield return this.ScaleTo(new Vector3(0.1f, 0.1f, 0.1f), 0).ScaleTo(Vector3.one, 0.3f);
        }

        public IEnumerator RunUICloseAnimation()
        {
            shaco.GameHelper.sound.Play($"{ShootMan.GlobalDefines.HOTUPDATE_ROOT}Audio/ui_hide.wav");
            yield return this.ScaleTo(Vector3.one, 0).ScaleTo(new Vector3(0.1f, 0.1f, 0.1f), 0.3f);
        }

        public void OnUIAnimationBreak()
        {
        }
    }
}